package com.ruoyi.framework.security;


import com.ruoyi.web.system.domain.LoginUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;

/**
 * 在线用户缓存 用于便捷获在线请求用户信息
 */
public enum OnlineUserCache {
    INSTANCE;
    private static final Logger log = LoggerFactory.getLogger(OnlineUserCache.class);
    private final HashMap<String, LoginUser> userHashMap = new HashMap<>();

    //根据token获取user
    public LoginUser getUser(String token) {
        for (String key : userHashMap.keySet()) {
            if (key.equals(token)) {
                log.debug("==========OnlineUserCache token 存在");
            }
        }
        return userHashMap.get(token);
    }

    //缓存user
    public void cacheUser(String token, LoginUser loginUser) {
        userHashMap.put(token, loginUser);
    }

    //移除user
    public void removeUser(String token) {
        userHashMap.remove(token);
    }


}